home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / bash_114.zip / bash-1.14.2 / builtins / ulimit.def < prev    next >
Encoding:
Text File  |  1994-07-02  |  16.3 KB  |  700 lines

  1. This file is ulimit.def, from which is created ulimit.c.
  2. It implements the builtin "ulimit" in Bash.
  3.  
  4. Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
  5.  
  6. This file is part of GNU Bash, the Bourne Again SHell.
  7.  
  8. Bash is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free
  10. Software Foundation; either version 1, or (at your option) any later
  11. version.
  12.  
  13. Bash is distributed in the hope that it will be useful, but WITHOUT ANY
  14. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License along
  19. with Bash; see the file COPYING.  If not, write to the Free Software
  20. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. $PRODUCES ulimit.c
  23.  
  24. $BUILTIN ulimit
  25. $FUNCTION ulimit_builtin
  26. $DEPENDS_ON !MINIX
  27. $SHORT_DOC ulimit [-SHacdmstfpnuv [limit]]
  28. Ulimit provides control over the resources available to processes
  29. started by the shell, on systems that allow such control.  If an
  30. option is given, it is interpreted as follows:
  31.  
  32.     -S    use the `soft' resource limit
  33.     -H    use the `hard' resource limit
  34.     -a    all current limits are reported
  35.     -c    the maximum size of core files created
  36.     -d    the maximum size of a process's data segment
  37.     -m    the maximum resident set size
  38.     -s    the maximum stack size
  39.     -t    the maximum amount of cpu time in seconds
  40.     -f    the maximum size of files created by the shell
  41.     -p    the pipe buffer size
  42.     -n    the maximum number of open file descriptors
  43.     -u    the maximum number of user processes
  44.     -v    the size of virtual memory 
  45.  
  46. If LIMIT is given, it is the new value of the specified resource.
  47. Otherwise, the current value of the specified resource is printed.
  48. If no option is given, then -f is assumed.  Values are in 1k
  49. increments, except for -t, which is in seconds, -p, which is in
  50. increments of 512 bytes, and -u, which is an unscaled number of
  51. processes.
  52. $END
  53.  
  54. #include <stdio.h>
  55. #include <sys/types.h>
  56. #include <sys/param.h>
  57. #include <errno.h>
  58. #include "../shell.h"
  59. #include "pipesize.h"
  60.  
  61. #if !defined (errno)
  62. extern int errno;
  63. #endif
  64.  
  65. #if defined (HAVE_RESOURCE)
  66. #  include <sys/time.h>
  67. #  include <sys/resource.h>
  68. #else
  69. #  include <sys/times.h>
  70. #endif
  71.  
  72. #if defined (_POSIX_VERSION)
  73. #  include <limits.h>
  74. #endif
  75.  
  76. /* Check for the most basic symbols.  If they aren't present, this
  77.    system's <sys/resource.h> isn't very useful to us. */
  78. #if !defined (RLIMIT_FSIZE) || defined (GETRLIMIT_MISSING)
  79. #  undef HAVE_RESOURCE
  80. #endif
  81.  
  82. /* **************************************************************** */
  83. /*                                    */
  84. /*            Ulimit builtin and Hacks.               */
  85. /*                                    */
  86. /* **************************************************************** */
  87.  
  88. /* Block size for ulimit operations. */
  89. #define ULIMIT_BLOCK_SIZE ((long)1024)
  90.  
  91. #define u_FILE_SIZE         0x001
  92. #define u_MAX_BREAK_VAL        0x002
  93. #define u_PIPE_SIZE        0x004
  94. #define u_CORE_FILE_SIZE    0x008
  95. #define u_DATA_SEG_SIZE        0x010
  96. #define u_PHYS_MEM_SIZE        0x020
  97. #define u_CPU_TIME_LIMIT    0x040
  98. #define u_STACK_SIZE        0x080
  99. #define u_NUM_OPEN_FILES    0x100
  100. #define u_MAX_VIRTUAL_MEM    0x200
  101. #define u_MAX_USER_PROCS    0x400
  102.  
  103. #define u_ALL_LIMITS        0x7ff
  104.  
  105. #if !defined (RLIM_INFINITY)
  106. #  define RLIM_INFINITY  0x7fffffff
  107. #endif
  108.  
  109. /* Some systems use RLIMIT_NOFILE, others use RLIMIT_OFILE */
  110. #if defined (HAVE_RESOURCE) && defined (RLIMIT_OFILE) && !defined (RLIMIT_NOFILE)
  111. #  define RLIMIT_NOFILE RLIMIT_OFILE
  112. #endif /* HAVE_RESOURCE && RLIMIT_OFILE && !RLIMIT_NOFILE */
  113.  
  114. #define LIMIT_HARD 0x01
  115. #define LIMIT_SOFT 0x02
  116.  
  117. static long shell_ulimit ();
  118. static long pipesize ();
  119. static long open_files ();
  120.  
  121. #if defined (HAVE_RESOURCE)
  122. static long getmaxvm ();
  123. #endif /* HAVE_RESOURCE */
  124.  
  125. static void print_specific_limits ();
  126. static void print_all_limits ();
  127.  
  128. static char t[2];
  129.  
  130. /* Return 1 if the limit associated with CMD can be raised from CURRENT
  131.    to NEW.  This is for USG systems without HAVE_RESOURCE, most of which
  132.    do not allow any user other than root to raise limits.  There are,
  133.    however, exceptions. */
  134. #if !defined (HAVE_RESOURCE)
  135. static int
  136. canraise (cmd, current, new)
  137.      int cmd;
  138.      long current, new;
  139. {
  140. #  if defined (HAVE_SETDTABLESIZE)
  141.   if (cmd == u_NUM_OPEN_FILES)
  142.     return (1);
  143. #  endif /* HAVE_SETDTABLSIZE */
  144.  
  145.   return ((current > new) || (current_user.uid == 0));
  146. }
  147. #endif /* !HAVE_RESOURCE */
  148.  
  149. /* Report or set limits associated with certain per-process resources.
  150.    See the help documentation in builtins.c for a full description.
  151.  
  152.    Rewritten by Chet Ramey 6/30/91. */
  153. int
  154. ulimit_builtin (list)
  155.      register WORD_LIST *list;
  156. {
  157.   register char *s;
  158.   int c, setting, cmd, mode, verbose_print, opt_eof;
  159.   int all_limits, specific_limits;
  160.   long current_limit, real_limit, limit = -1L;
  161.   long block_factor;
  162.  
  163.   c = mode = verbose_print = opt_eof = 0;
  164.  
  165.   do
  166.     {
  167.       cmd = setting = all_limits = specific_limits = 0;
  168.       block_factor = ULIMIT_BLOCK_SIZE;
  169.  
  170.       /* read_options: */
  171.       if (list && !opt_eof && *list->word->word == '-')
  172.     {
  173.       s = &(list->word->word[1]);
  174.       list = list->next;
  175.  
  176.       while (*s && (c = *s++))
  177.         {
  178.           switch (c)
  179.         {
  180. #define ADD_CMD(x) { if (cmd) specific_limits++; cmd |= (x); }
  181.  
  182.         case '-':    /* ulimit -- */
  183.           opt_eof++;
  184.           break;
  185.           
  186.         case 'a':
  187.           all_limits++;
  188.           break;
  189.  
  190.         case 'f':
  191.           ADD_CMD (u_FILE_SIZE);
  192.           break;
  193.  
  194. #if defined (HAVE_RESOURCE)
  195.         /* -S and -H are modifiers, not real options.  */
  196.         case 'S':
  197.           mode |= LIMIT_SOFT;
  198.           break;
  199.  
  200.         case 'H':
  201.           mode |= LIMIT_HARD;
  202.           break;
  203.  
  204.         case 'c':
  205.           ADD_CMD (u_CORE_FILE_SIZE);
  206.           break;
  207.  
  208.         case 'd':
  209.           ADD_CMD (u_DATA_SEG_SIZE);
  210.           break;
  211.  
  212. #if !defined (USGr4)
  213.         case 'm':
  214.           ADD_CMD (u_PHYS_MEM_SIZE);
  215.           break;
  216. #endif /* USGr4 */
  217.  
  218.         case 't':
  219.           ADD_CMD (u_CPU_TIME_LIMIT);
  220.           block_factor = 1;    /* seconds */
  221.           break;
  222.  
  223.         case 's':
  224.           ADD_CMD (u_STACK_SIZE);
  225.           break;
  226.  
  227.         case 'v':
  228.           ADD_CMD (u_MAX_VIRTUAL_MEM);
  229.           block_factor = 1;
  230.           break;
  231.  
  232.         case 'u':
  233.           ADD_CMD (u_MAX_USER_PROCS);
  234.           block_factor = 1;
  235.           break;
  236.  
  237. #endif /* HAVE_RESOURCE */
  238.  
  239.         case 'p':
  240.           ADD_CMD (u_PIPE_SIZE);
  241.           block_factor = 512;
  242.           break;
  243.  
  244.         case 'n':
  245.           ADD_CMD (u_NUM_OPEN_FILES);
  246.           block_factor = 1;
  247.           break;
  248.  
  249.         default:        /* error_case: */
  250.           t[0] = c;
  251.           t[1] = '\0';
  252.           bad_option (t);
  253. #if !defined (HAVE_RESOURCE)
  254.           builtin_error("usage: ulimit [-afnp] [new limit]");
  255. #else
  256.           builtin_error("usage: ulimit [-SHacmdstfnpuv] [new limit]");
  257. #endif
  258.           return (EX_USAGE);
  259.         }
  260.         }
  261.     }
  262.  
  263.     if (all_limits)
  264.       {
  265.         print_all_limits (mode);
  266.         return (EXECUTION_SUCCESS);
  267.       }
  268.  
  269.     if (specific_limits)
  270.       {
  271.         print_specific_limits (cmd, mode);
  272.         if (list)
  273.           verbose_print++;
  274.         continue;
  275.       }
  276.  
  277.     if (cmd == 0)
  278.       cmd = u_FILE_SIZE;
  279.  
  280.      /* If an argument was supplied for the command, then we want to
  281.        set the limit.  Note that `ulimit something' means a command
  282.        of -f with argument `something'. */
  283.     if (list)
  284.       {
  285.         if (opt_eof || (*list->word->word != '-'))
  286.           {
  287.         s = list->word->word;
  288.         list = list->next;
  289.  
  290.         if (STREQ (s, "unlimited"))
  291.           limit = RLIM_INFINITY;
  292.         else if (all_digits (s))
  293.           limit = string_to_long (s);
  294.         else
  295.           {
  296.             builtin_error ("bad non-numeric arg `%s'", s);
  297.             return (EXECUTION_FAILURE);
  298.           }
  299.         setting++;
  300.           }
  301.         else if (!opt_eof)
  302.           verbose_print++;
  303.       }
  304.  
  305.       if (limit == RLIM_INFINITY)
  306.     block_factor = 1;
  307.  
  308.       real_limit = limit * block_factor;
  309.  
  310.       /* If more than one option is given, list each in a verbose format,
  311.      the same that is used for -a. */
  312.       if (!setting && verbose_print)
  313.     {
  314.       print_specific_limits (cmd, mode);
  315.       continue;
  316.     }
  317.  
  318.       current_limit = shell_ulimit (cmd, real_limit, 0, mode);
  319.  
  320.       if (setting)
  321.     {
  322. #if !defined (HAVE_RESOURCE)
  323.       /* Most USG systems do not most allow limits to be raised by any
  324.          user other than root.  There are, however, exceptions. */
  325.       if (canraise (cmd, current_limit, real_limit) == 0)
  326.         {
  327.           builtin_error ("cannot raise limit: %s", strerror (EPERM));
  328.           return (EXECUTION_FAILURE);
  329.         }
  330. #endif /* !HAVE_RESOURCE */
  331.  
  332.       if (shell_ulimit (cmd, real_limit, 1, mode) == -1L)
  333.         {
  334.           builtin_error ("cannot raise limit: %s", strerror (errno));
  335.           return (EXECUTION_FAILURE);
  336.         }
  337.  
  338.       continue;
  339.     }
  340.       else
  341.     {
  342.       if (current_limit < 0)
  343.         builtin_error ("cannot get limit: %s", strerror (errno));
  344.       else if (current_limit != RLIM_INFINITY)
  345.         printf ("%ld\n", (current_limit / block_factor));
  346.       else
  347.         printf ("unlimited\n");
  348.     }
  349.     }
  350.   while (list);
  351.  
  352.   return (EXECUTION_SUCCESS);
  353. }
  354.  
  355. /* The ulimit that we call from within Bash.
  356.  
  357.    WHICH says which limit to twiddle; SETTING is non-zero if NEWLIM
  358.    contains the desired new limit.  Otherwise, the existing limit is
  359.    returned.  If mode & LIMIT_HARD, the hard limit is used; if
  360.    mode & LIMIT_SOFT, the soft limit.  Both may be set by specifying
  361.    -H and -S; if both are specified, or if neither is specified, the
  362.    soft limit will be returned.
  363.  
  364.    Systems without BSD resource limits can specify only u_FILE_SIZE.
  365.    This includes most USG systems.
  366.  
  367.    Chet Ramey supplied the BSD resource limit code. */
  368. static long
  369. shell_ulimit (which, newlim, setting, mode)
  370.      int which, setting, mode;
  371.      long newlim;
  372. {
  373. #if defined (HAVE_RESOURCE)
  374.   struct rlimit limit;
  375.   int cmd;
  376.  
  377.   if (mode == 0)
  378.     mode |= LIMIT_SOFT;
  379. #endif
  380.  
  381.   switch (which)
  382.     {
  383. #if !defined (HAVE_RESOURCE)
  384.  
  385.     case u_FILE_SIZE:
  386.       if (!setting)
  387.     {
  388.       /* ulimit () returns a number that is in 512 byte blocks, thus we
  389.          must multiply it by 512 to get back to bytes.  This is false
  390.          only under HP/UX 6.x. */
  391.       long result;
  392.  
  393.       result = ulimit (1, 0L);
  394.  
  395. #  if defined (hpux) && !defined (_POSIX_VERSION)
  396.       return (result);
  397. #  else
  398.       return (result * 512);
  399. #  endif /* hpux 6.x */
  400.     }
  401.       else
  402.     return (ulimit (2, newlim / 512L));
  403.  
  404.       break;
  405.  
  406. #else /* defined (HAVE_RESOURCE) */
  407.  
  408.     case u_FILE_SIZE:
  409.       cmd = RLIMIT_FSIZE;
  410.       goto do_ulimit;
  411.  
  412.     case u_CORE_FILE_SIZE:
  413.       cmd = RLIMIT_CORE;
  414.       goto do_ulimit;
  415.  
  416.     case u_DATA_SEG_SIZE:
  417.       cmd = RLIMIT_DATA;
  418.       goto do_ulimit;
  419.  
  420. #if !defined (USGr4)
  421.     case u_PHYS_MEM_SIZE:
  422. #  if defined (RLIMIT_RSS)
  423.       cmd = RLIMIT_RSS;
  424. #  else /* !RLIMIT_RSS */
  425.       errno = EINVAL;
  426.       return (-1L);
  427. #  endif /* !RLIMIT_RSS */
  428.  
  429.       goto do_ulimit;
  430. #endif /* USGr4 */
  431.  
  432.     case u_CPU_TIME_LIMIT:
  433.       cmd = RLIMIT_CPU;
  434.       goto do_ulimit;
  435.  
  436.     case u_STACK_SIZE:
  437.       cmd = RLIMIT_STACK;
  438.  
  439.     do_ulimit:
  440.  
  441.       if (getrlimit (cmd, &limit) != 0)
  442.     return (-1L);
  443.  
  444.       if (!setting)
  445.     {
  446.       if (mode & LIMIT_SOFT)
  447.         return (limit.rlim_cur);
  448.       else
  449.         return (limit.rlim_max);
  450.     }
  451.       else
  452.     {
  453.       if (mode & LIMIT_SOFT)
  454.         {
  455.           /* Non-root users are only allowed to raise a limit up to the
  456.          hard limit, not to infinity. */
  457.           if (current_user.euid != 0 && newlim == RLIM_INFINITY)
  458.         limit.rlim_cur = limit.rlim_max;
  459.           else
  460.         limit.rlim_cur = newlim;
  461.         }
  462.       if (mode & LIMIT_HARD)
  463.         limit.rlim_max = newlim;
  464.  
  465.       return (setrlimit (cmd, &limit));
  466.     }
  467.  
  468.       break;
  469.  
  470. #endif /* HAVE_RESOURCE */
  471.  
  472.       /* You can't get or set the pipe size with getrlimit, so we have to
  473.      cheat.  */
  474.     case u_PIPE_SIZE:
  475.       if (setting)
  476.     {
  477.       errno = EINVAL;
  478.       return (-1L);
  479.     }
  480.       return (pipesize ());
  481.  
  482.     case u_NUM_OPEN_FILES:
  483.       if (setting)
  484.     {
  485. #if defined (HAVE_RESOURCE) && defined (RLIMIT_NOFILE)
  486.       cmd = RLIMIT_NOFILE;
  487.       goto do_ulimit;
  488. #else
  489. #  if defined (HAVE_SETDTABLESIZE)
  490.       return (setdtablesize (newlim));
  491. #  else
  492.       errno = EINVAL;
  493.       return (-1L);
  494. #  endif /* HAVE_SETDTABLESIZE */
  495. #endif /* !HAVE_RESOURCE || !RLIMIT_NOFILE */
  496.     }
  497.       else
  498.     return (open_files (mode));
  499.  
  500.     case u_MAX_VIRTUAL_MEM:
  501.       if (setting)
  502.     {
  503.       errno = EINVAL;
  504.       return (-1L);
  505.     }
  506.       else
  507.     {
  508. #if defined (HAVE_RESOURCE)
  509.       return (getmaxvm (mode));
  510. #else /* !HAVE_RESOURCE */
  511.       errno = EINVAL;
  512.       return (-1L);
  513. #endif /* !HAVE_RESOURCE */
  514.     }
  515.  
  516.     case u_MAX_USER_PROCS:
  517. #if defined (HAVE_RESOURCE) && defined (RLIMIT_NPROC)
  518.       cmd = RLIMIT_NPROC;
  519.       goto do_ulimit;
  520. #else /* !HAVE_RESOURCE || !RLIMIT_NPROC */
  521.       errno = EINVAL;
  522.       return (-1L);
  523. #endif /* !HAVE_RESOURCE || !RLIMIT_NPROC */
  524.       
  525.     default:
  526.       errno = EINVAL;
  527.       return (-1L);
  528.     }
  529. }
  530.  
  531. #if defined (HAVE_RESOURCE)
  532. static long
  533. getmaxvm (mode)
  534.      int mode;
  535. {
  536.   struct rlimit rl;
  537.  
  538. #if defined (RLIMIT_VMEM)
  539.   if (getrlimit (RLIMIT_VMEM, &rl) < 0)
  540.     return (-1L);
  541.   else
  542.     return (((mode & LIMIT_SOFT) ? rl.rlim_cur : rl.rlim_max) / 1024L);
  543. #else /* !RLIMIT_VMEM */
  544.   unsigned long maxdata, maxstack;
  545.  
  546.   if (getrlimit (RLIMIT_DATA, &rl) < 0)
  547.     return (-1L);
  548.   else
  549.     maxdata = (mode & LIMIT_SOFT) ? rl.rlim_cur : rl.rlim_max;
  550.  
  551.   if (getrlimit (RLIMIT_STACK, &rl) < 0)
  552.     return (-1L);
  553.   else
  554.     maxstack = (mode & LIMIT_SOFT) ? rl.rlim_cur : rl.rlim_max;
  555.  
  556.   /* Protect against overflow. */
  557.   return ((maxdata / 1024L) + (maxstack / 1024L));
  558. #endif /* !RLIMIT_VMEM */
  559. }
  560. #endif /* HAVE_RESOURCE */
  561.  
  562. static long
  563. open_files (mode)
  564.      int mode;
  565. {
  566. #if !defined (RLIMIT_NOFILE)
  567.   return ((long)getdtablesize ());
  568. #else
  569.   struct rlimit rl;
  570.  
  571.   getrlimit (RLIMIT_NOFILE, &rl);
  572.   if (mode & LIMIT_SOFT)
  573.     return (rl.rlim_cur);
  574.   else
  575.     return (rl.rlim_max);
  576. #endif
  577. }
  578.  
  579. static long
  580. pipesize ()
  581. {
  582. #if defined (PIPE_BUF)
  583.   /* This is defined on Posix systems. */
  584.   return ((long) PIPE_BUF);
  585. #else
  586. #  if defined (PIPESIZE)
  587.   /* This is defined by running a program from the Makefile. */
  588.   return ((long) PIPESIZE);
  589. #  else
  590.   errno = EINVAL;
  591.   return (-1L);
  592. #  endif /* PIPESIZE */
  593. #endif /* PIPE_BUF */
  594. }
  595.  
  596. /* ulimit(2) returns information about file size limits in terms of 512-byte
  597.    blocks.  This is the factor by which to divide to turn it into information
  598.    in terms of 1024-byte blocks.  Except for hpux 6.x, which returns it in
  599.    terms of bytes. */
  600. #if !defined (hpux) || defined (_POSIX_VERSION)
  601. #  define ULIMIT_DIVISOR 2
  602. #else
  603. #  define ULIMIT_DIVISOR 1024
  604. #endif
  605.  
  606. #if defined (HAVE_RESOURCE)
  607.  
  608. typedef struct {
  609.   int  option_cmd;        /* The ulimit command for this limit. */
  610.   int  parameter;        /* Parameter to pass to getrlimit (). */
  611.   int  block_factor;        /* Blocking factor for specific limit. */
  612.   char *description;        /* Descriptive string to output. */
  613. } BSD_RESOURCE_LIMITS;
  614.  
  615. static BSD_RESOURCE_LIMITS limits[] = {
  616.   { u_CORE_FILE_SIZE, RLIMIT_CORE,  1024, "core file size (blocks)" },
  617.   { u_DATA_SEG_SIZE,  RLIMIT_DATA,  1024, "data seg size (kbytes)" },
  618.   { u_FILE_SIZE,      RLIMIT_FSIZE, 1024, "file size (blocks)" },
  619. #if !defined (USGr4) && defined (RLIMIT_RSS)
  620.   { u_PHYS_MEM_SIZE,  RLIMIT_RSS,   1024, "max memory size (kbytes)" },
  621. #endif /* USGr4 && RLIMIT_RSS */
  622.   { u_STACK_SIZE,     RLIMIT_STACK, 1024, "stack size (kbytes)" },
  623.   { u_CPU_TIME_LIMIT, RLIMIT_CPU,      1, "cpu time (seconds)" },
  624. #if defined (RLIMIT_NPROC)
  625.   { u_MAX_USER_PROCS, RLIMIT_NPROC,    1, "max user processes" },
  626. #endif /* RLIMIT_NPROC */
  627.   { 0, 0, 0, (char *)NULL }
  628. };
  629.  
  630. static void
  631. print_bsd_limit (i, mode)
  632.      int i, mode;
  633. {
  634.   struct rlimit rl;
  635.   long limit;
  636.  
  637.   getrlimit (limits[i].parameter, &rl);
  638.   if (mode & LIMIT_HARD)
  639.     limit = rl.rlim_max;
  640.   else
  641.     limit = rl.rlim_cur;
  642.   printf ("%-25s", limits[i].description);
  643.   if (limit == RLIM_INFINITY)
  644.     printf ("unlimited\n");
  645.   else
  646.     printf ("%ld\n", limit / limits[i].block_factor);
  647. }
  648.  
  649. static void
  650. print_specific_bsd_limits (cmd, mode)
  651.      int cmd, mode;
  652. {
  653.   register int i;
  654.  
  655.   for (i = 0; limits[i].option_cmd; i++)
  656.     if (cmd & limits[i].option_cmd)
  657.       print_bsd_limit (i, mode);
  658. }
  659. #endif /* HAVE_RESOURCE */
  660.  
  661. /* Print the limits corresponding to a specific set of resources.  This is
  662.    called when an option string contains more than one character (e.g. -at),
  663.    because limits may not be specified with that kind of argument. */
  664. static void
  665. print_specific_limits (cmd, mode)
  666.      int cmd, mode;
  667. {
  668.   if (mode == 0)
  669.     mode |= LIMIT_SOFT;
  670.  
  671. #if defined (HAVE_RESOURCE)
  672.   print_specific_bsd_limits (cmd, mode);
  673. #else /* !HAVE_RESOURCE */
  674.   if (cmd & u_FILE_SIZE)
  675.     printf ("%-25s%ld\n",
  676.         "file size (blocks)", ulimit (1, 0L) / ULIMIT_DIVISOR);
  677. #endif /* !HAVE_RESOURCE */
  678.  
  679.   if (cmd & u_PIPE_SIZE)
  680.     printf ("%-25s%ld\n", "pipe size (512 bytes)", (pipesize () / 512));
  681.  
  682.   if (cmd & u_NUM_OPEN_FILES)
  683.     printf ("%-25s%ld\n", "open files", open_files (mode));
  684.  
  685. #if defined (HAVE_RESOURCE)
  686.   if (cmd & u_MAX_VIRTUAL_MEM)
  687.     printf ("%-25s%ld\n", "virtual memory (kbytes)", getmaxvm (mode));
  688. #endif /* HAVE_RESOURCE */
  689. }
  690.  
  691. static void
  692. print_all_limits (mode)
  693.      int mode;
  694. {
  695.   if (mode == 0)
  696.     mode |= LIMIT_SOFT;
  697.  
  698.   print_specific_limits (u_ALL_LIMITS, mode);
  699. }
  700.